package com.example.mrzhou.lvmm.commom.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

/**
 * Created by Mr.zhou on 2016/10/28.
 */

public class MyScollView extends ScrollView {

    private OnScrollToBottomListener mOnScrollToBottomListener;

    public MyScollView(Context context) {
        super(context);
    }

    public MyScollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyScollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        // 滑动的距离加上本身的高度与子View的高度对比
        if (t + getHeight() >= getChildAt(0).getMeasuredHeight()) {
            // ScrollView滑动到底部
            if (mOnScrollToBottomListener != null) {
                mOnScrollToBottomListener.onScrollToBottom();
            }
        } else {
            if (mOnScrollToBottomListener != null) {
                mOnScrollToBottomListener.onNotScrollToBottom();
            }
        }
    }

    public void setScrollToBottomListener(OnScrollToBottomListener listener) {
        this.mOnScrollToBottomListener = listener;
    }

    public interface OnScrollToBottomListener {
        void onScrollToBottom();

        void onNotScrollToBottom();
    }
}
